import 'package:contract_manager/pages/contract_entry/contract_entry_binding.dart';
import 'package:contract_manager/pages/contract_entry/contract_entry_view.dart';
import 'package:contract_manager/pages/contract_list/contract_list_binding.dart';
import 'package:contract_manager/pages/contract_list/contract_list_view.dart';
import 'package:contract_manager/pages/import_contract/import_contract_binding.dart';
import 'package:contract_manager/pages/import_contract/import_contract_view.dart';
import 'package:contract_manager/pages/reminder/reminder_binding.dart';
import 'package:contract_manager/pages/reminder/reminder_view.dart';
import 'package:contract_manager/router/app_pages.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class HomeController extends GetxController {
  final count = 0.obs;

  String userName = 'burnish';

  Route? onGenerateRoute(RouteSettings settings) {
    if (settings.name == AppRoutes.ContractList) {
      return GetPageRoute(
        settings: settings,
        page: () => const ContractListPage(),
        binding: ContractListBinding(),
      );
    } else if (settings.name == AppRoutes.ImportContract) {
      return GetPageRoute(
        settings: settings,
        page: () => const ImportContractPage(),
        binding: ImportContractBinding(),
      );
    } else if (settings.name == AppRoutes.reminderList) {
      return GetPageRoute(
        settings: settings,
        page: () => ReminderView(),
        binding: ReminderBinding(),
      );
    } else if (settings.name == AppRoutes.newContract) {
      return GetPageRoute(
        settings: settings,
        page: () => ContractEntryView(),
        binding: ContractEntryBinding(),
      );
    }
  }

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
  }

  @override
  void onReady() {}

  @override
  void onClose() {}

  void increment() => count.value++;

  final currentIndex = 0.obs;

  void changePage(int index) {
    currentIndex.value = index;
    switch (index) {
      case 0:
        Get.offAndToNamed(AppRoutes.ContractList, id: 1);
        break;
      case 1:
        Get.offAndToNamed(AppRoutes.ImportContract, id: 1);
        break;
      case 2:
        Get.offAndToNamed(AppRoutes.newContract, id: 1);
        break;
      case 3:
        Get.offAndToNamed(AppRoutes.reminderList, id: 1);
        break;
    }
  }

  void changeUserName() {
    userName = "User name changed";
    update();
  }
}
